from fastapi import APIRouter
from app.services.rps import rps, money_flow
import pandas as pd

router = APIRouter(prefix="/api/sector")
@router.get("/rank")
def sector_rank(period: int = 5, top: int = 10):
    df = rps(period)
    if df.empty:                       # 空则降级
        df = pd.DataFrame([
            {'ind': 'BK0475', 'rps': 98.5, 'money_flow': 1.2e4},
            {'ind': 'BK0839', 'rps': 96.2, 'money_flow': 8.3e3},
        ])
    return df.head(top).to_dict(orient='records')
